-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
release-22.2: opt: correctly track UDTs and UDFs for query cache invalidation #100223
release-22.2: opt: correctly track UDTs and UDFs for query cache invalidation #100223
Conversation
This commit performs some refactoring for the way data source objects are tracked in `opt.Metadata` in order to make future changes to UDT and UDF dependency tracking easier. More particularly, UDTs and UDFs will be able to re-resolve any references by name. This is necessary in order to handle cases where changes to the search-path cause names in the query to resolve to different objects. Release note: None
Previously, it was possible for invalid queries to be kept in the cache after a schema change, since user-defined types were tracked only by OID. This missed cases where the search path changed which object a name in the query resolved to (or whether it resolved at all). This patch fixes this behavior by tracking UDT references by name, similar to what was already done for data sources. This ensures that the query staleness check doesn't miss changes to the search path. Fixes cockroachdb#96674 Release note (bug fix): Fixed a bug that could prevent a cached query with a user-defined type reference from being invalidated even after a schema change that should prevent the type from being resolved.
Thanks for opening a backport. Please check the backport criteria before merging:
If some of the basic criteria cannot be satisfied, ensure that the exceptional criteria are satisfied within.
Add a brief release justification to the body of your PR to justify this backport. Some other things to consider:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 4 files at r1, 5 of 5 files at r2, 10 of 10 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @michae2)
This patch adds tracking for user-defined functions in `opt.Metadata`. This ensures that the query cache will be correctly invalidated after a schema change or search-path change that could change the query's semantics, or cause it to error. Fixes cockroachdb#93082 Fixes cockroachdb#93321 Release note (bug fix): Fixed a bug that could prevent a cached query from being invalidated when a UDF referenced by that query was altered or dropped.
It is possible to define a user-defined function with the same signature as a builtin function. Normally, an unqualified function call will resolve to the builtin function because its schema will be first in the search path. However, it is possible to modify the search path, so that the same function call can resolve to different functions on different executions. Example: ``` CREATE FUNCTION public.abs(val INT) RETURNS INT CALLED ON NULL INPUT LANGUAGE SQL AS $$ SELECT val+100 $$; SELECT abs(1); --This should resolve to the builtin abs(). SET search_path = public, pg_catalog; SELECT abs(1); --This should resolve to the udf abs(). ``` Fixes cockroachdb#97757 Release note (bug fix): Fixed a bug existing from when user-defined functions were introduced that could cause a function call to resolve to the wrong function after changes to the schema search path.
fce6b1e
to
44f57e2
Compare
TFTR! |
Backport:
Please see individual PRs for details.
/cc @cockroachdb/release
Release Justification: low-risk bug fix for rare incorrect results for UDTs and UDFs